#!/bin/sh
set -e

QMAKE_ARGS="QDJANGO_PROFILE=true"

case "$CONFIG" in
*static)
    QMAKE_ARGS="$QMAKE_ARGS QDJANGO_LIBRARY_TYPE=staticlib"
    ;;
esac

# compile
qmake $QMAKE_ARGS
make

# run tests
QDJANGO_DB_DRIVER=QSQLITE QDJANGO_DB_NAME=:memory: make check
QDJANGO_DB_DRIVER=QSQLITE QDJANGO_DB_NAME=/tmp/qdjango_test.db make check
QDJANGO_DB_DRIVER=QMYSQL QDJANGO_DB_NAME=qdjango_test QDJANGO_DB_USER=root make check
QDJANGO_DB_DRIVER=QPSQL QDJANGO_DB_NAME=qdjango_test QDJANGO_DB_USER=postgres make check
exit 0

# generate coverage report
TRACEFILE=coverage.info
rm -f $TRACEFILE
lcov --capture --directory src -o $TRACEFILE --no-external
lcov --remove $TRACEFILE \*moc_\* -o $TRACEFILE.clean
mv $TRACEFILE.clean $TRACEFILE

rm -rf coverage
genhtml -o coverage $TRACEFILE
echo "ok"
